/*
 * @lc app=leetcode.cn id=1030 lang=javascript
 *
 * [1030] 距离顺序排列矩阵单元格
 */

// @lc code=start
/**
 * @param {number} rows
 * @param {number} cols
 * @param {number} rCenter
 * @param {number} cCenter
 * @return {number[][]}
 */
var allCellsDistOrder = function (rows, cols, rCenter, cCenter) {
  const nums = [];
  for (let i = 0; i < rows; i++) {
    for (let j = 0; j < cols; j++) {
      nums.push([[i, j], Math.abs(i - rCenter) + Math.abs(j - cCenter)]);
    }
  }
  return nums.sort((a, b) => a[1] - b[1]).map(([[a, b]]) => [a, b]);
};
// @lc code=end

